const App = getApp();
// 工具类
import Util from '../../../../utils/util.js';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    teamId: 0,
    list:[],
    page:1,// 当前页码
    last_page:1,
    scrollHeight: null,
    no_more: false, // 没有更多数据
    isLoading: true, // 是否正在加载中
    showQRCodePopup:false,
    QRCodeImage:""
  },
 //控制左上角自带返回键的链接
  onUnload: function () {
    wx.reLaunch({
      url: '/pages/user/index'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    that.setData({
      isLogin: App.checkIsLogin(),
    });
    if (that.data.isLogin) {
      //获取服务队
      that.setData({
        teamId: App.checkTeam()
      });
       //设置页面高度
       that.setListHeight();
       //获取购物车列表
       that.getDataList();
    }
  },

 //获取数据列表
  getDataList(isPage, page){
  var obj = {
    team_id:this.data.teamId,
    page: page || 1
  }
  console.log(obj)
  let _this = this;
  App._get('activity/examineLists', obj, function(result) {
    let resList = result.data.list,
        dataList = _this.data.list;
    if (isPage == true) {
      _this.setData({
        list: dataList.concat(resList.data),
        isLoading: false,
        last_page: resList.last_page,
      });
    } else {
      _this.setData({
        list: resList.data,
        isLoading: false,
        last_page: resList.last_page,
      });
    }
  });
  },
  
  // 发布活动跳转
  newsDetail(e){
    let nid = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: './detail?nid=' + nid,
    })
  },

  /**
   * 下拉到底加载数据
   */
  bindDownLoad() {
    // 已经是最后一页
    console.log("翻页");
    console.log("page =",this.data.page)
    console.log("last_page =",this.data.last_page)
    if (this.data.page >= this.data.last_page) {
      this.setData({
        no_more: true
      });
      return false;
    }
    // 加载下一页列表
    this.getDataList(true, ++this.data.page);
  },

  /**
   * 设置文章列表高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 98), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    console.log(
      systemInfo.windowHeight
    );
    this.setData({
      scrollHeight
    });
  },

  
// 下载图片
  bindsaveimage:function(){
    wx.getImageInfo({
      src: this.data.QRCodeImage,//这里放你要下载图片的数组(多张) 或 字符串(一张) 下面代码不用改动
      success: function (ret) {
        var path = ret.path;
        wx.saveImageToPhotosAlbum({
          filePath: path,
          success(result) {
            console.log("成功");
            wx.hideLoading();
            wx.showToast({
              title: '下载图片成功',
              duration: 2000,
              mask: true,
            });
          },
          fail(result) {
            console.log("失败,你取消了" + JSON.stringify(result))
            console.log(path);
            wx.openSetting({
              success: (res) => {
                console.log(res);
              }
            })
          }
        });
      }
    });
  }

})